﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.DAL;
using Gift.Model;

namespace WebSite.admin.warehouse
{
    public partial class warehouse : BaseAdmin
    {

        tbWarehouse oWarehous;
        readonly DALWarehouse theWarehouse = new DALWarehouse();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindWarehouse();

            }
        }

        void BindWarehouse()
        {
            if (Request.QueryString["ot"] == "ed")
            {
                oWarehous = theWarehouse.GetModel(int.Parse(Request.QueryString["id"]));
                this.txtWareName.Text = oWarehous.warehouseName;
                this.txtbh.Text = oWarehous.warebh;
                this.txtPhone.Text = oWarehous.phone;
                this.txtAddress.Text = oWarehous.address;
                this.txtName.Text = oWarehous.warehouseMan;
                this.txtContent.Text = oWarehous.content;

            }
        }



        public string HeaderHtml
        {
            get
            {
                string sHead = "";
                if (!string.IsNullOrEmpty(Request.QueryString["id"]) && Request.QueryString["id"] != "0")
                {

                    oWarehous = this.theWarehouse.GetModel(int.Parse(Request.QueryString["id"]));

                    sHead = string.Format(" <div  class=\"navgater\"><img src=\"../images/module.gif\" width=\"20\" height=\"22\" alt=\"\"/> "
                                             + " 仓库名称：{0} "
                                             + " <a style=\" display:block; float:right;\" href=\"javascript:location.href='warehouseList.aspx';\" ><img src=\"../images/history.gif\" border=\"0\" /></a>"
                                             + " </div>"
                                             , oWarehous.warehouseName
                                             );
                    
                }
                else
                {
                    sHead = " <div  class=\"navgater\"><img src=\"../images/module.gif\" width=\"20\" height=\"22\" alt=\"\"/> "
                                           + " 添加仓库 "
                                           + " <a style=\" display:block; float:right;\" href=\"javascript:location.href='warehouseList.aspx';\" ><img src=\"../images/history.gif\" border=\"0\" /></a>"
                                           + " </div>";
                }
                return sHead;

            }


        }



        protected void btnSubmitForm1_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["ot"] == "ed")
            {
                oWarehous = theWarehouse.GetModel(int.Parse(Request.QueryString["id"]));
                oWarehous.warehouseName = this.txtWareName.Text;
                oWarehous.warebh = this.txtbh.Text;
                oWarehous.phone = this.txtPhone.Text;
                oWarehous.address = this.txtAddress.Text;
                oWarehous.warehouseMan = this.txtName.Text;
                oWarehous.content = this.txtContent.Text;
                oWarehous.editDate = DateTime.Now;
                oWarehous.flag = 1;

                if (theWarehouse.Update(oWarehous))
                {
                    ExtAspNet.Alert.Show("修改成功！", "", " window.location.href='warehouseList.aspx';");

                   // base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");window.location.href='warehouseList.aspx';</script>");
                }
                else
                {
                    ExtAspNet.Alert.Show("更新失败！");

                  //  base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                }
                ExtAspNet.Alert.Show("修改成功！", "", "window.location.href='warehouseList.aspx';");
            }
            else
            {
                oWarehous = new tbWarehouse();
                oWarehous.warehouseName = this.txtWareName.Text;
                oWarehous.warebh = this.txtbh.Text;
                oWarehous.phone = this.txtPhone.Text;
                oWarehous.address = this.txtAddress.Text;
                oWarehous.warehouseMan = this.txtName.Text;
                oWarehous.content = this.txtContent.Text;
                oWarehous.createTime = DateTime.Now;
                oWarehous.creater = int.Parse(base.AdminUserId);
                oWarehous.editDate = DateTime.Now;
                oWarehous.flag = 1;

                theWarehouse.Add(oWarehous);
                ExtAspNet.Alert.Show("添加成功！", "", " window.location.href='warehouseList.aspx';");
            }

        }
    }
}